#!/bin/bash

echo "+++++++++++++++++++++++ $(cd `dirname $0`; pwd)/$(basename $0) +++++++++++++++++++++++++"

# 当前脚本所在目录
v_d_current=$(cd `dirname $0`; pwd)
# 当前脚本的配置信息
v_f_settings=${v_d_current}/settings
# 当前脚本的环境变量配置
v_env_filename=`ls ${v_d_current} | grep env.sh`
v_f_env=${v_d_current}/${v_env_filename}
# 环境变量文件
v_f_profile=${g_d_profile}/${v_env_filename}

# 检查配置文件是否存在
if [ ! -f ${v_f_settings} ]; then
    echo "settings file does not exist : $v_f_settings"
    exit -1
fi

# 加载配置信息
source ${g_f_util_properties} "load" ${v_f_settings}

# 检查环境变量文件是否存在
if [ ! -f ${v_f_env} ]; then
    echo "env file does not exist : $v_f_env"
    exit -1
fi

# 检查安装目录是否存在
if [ ! -n "$install_dir" ] || [ ! -d ${install_dir} ]; then
    echo "installation directory does not exist : $install_dir"
    exit -1
fi

# 检查安装包是否存在
if [ ! -n "$install_file" ] || [ ! -f ${install_file} ]; then
    echo "installation file does not exist : $install_file"
    exit -1
fi
# 解压安装包到安装目录
tar -zxf ${install_file} -C ${install_dir}
# 建立软连接
v_d_home=${install_dir}/maven
ln -fs ${install_dir}/apache-maven* ${v_d_home}
# 设置环境变量
\cp ${v_f_env} ${v_f_profile}
${g_f_util_replace} -s "$v_f_env" -t "$v_f_profile" HOME=${v_d_home}
source /etc/profile

echo "PATH : $PATH"
echo "M2_HOME : $M2_HOME"
mvn -version
exit -1